package spit;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JPanel;

public class EndGamePanel extends JPanel {
	
	final private String winGame = "You've won the game!";
	final private String loseGame = "The computer has won the game!";
	
	String message;
	
	boolean won;
	
	public EndGamePanel()
	{
		message = "";
	}
	
	public void setWon(boolean winStatus)
	{
		won = winStatus;
    	if (won)
    	{
    		message = winGame;
    	}
    	else
    	{
    		message = loseGame;
    	}
    	System.out.println(message);
    }
	
	
    protected void paintComponent(Graphics g) {
        // call super.paintComponent to get default Swing 
        // painting behavior (opaque honored, etc.)
        super.paintComponent(g);
        int x = 0;
        int y = 0;
        int width = getWidth();
        int height = getHeight();
        
        Graphics2D g2d = (Graphics2D) g;
        
        drawBlack(g2d);
        
        drawMessage(g2d);
       
            
    }

    public void drawBlack(Graphics2D g2d)
    {
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.6f));
        g2d.setColor(Color.BLACK);
        g2d.fillRect(0, 0, getWidth(), getHeight());
    }
    
    public void drawMessage(Graphics2D g2d)
    {
    	if(won)
    	{
            g2d.setComposite(AlphaComposite.getInstance(
                    AlphaComposite.SRC_OVER, 0.7f));
            g2d.setColor(Color.YELLOW);
            g2d.setFont(new Font("Serif", Font.BOLD, 40));
            g2d.drawString(message, getWidth()/4, getHeight()/2);
    	}
    	else
    	{
            g2d.setComposite(AlphaComposite.getInstance(
                    AlphaComposite.SRC_OVER, 0.7f));
            g2d.setColor(Color.YELLOW);
            g2d.setFont(new Font("Serif", Font.BOLD, 40));
            g2d.drawString(message, getWidth()/6, getHeight()/2);
    	}
    	


        
    }
    
}
